package com.briup.searchengine.handle;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author adam
 * @date 2023/2/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WebPageItem implements WritableComparable<WebPageItem> {
    //主键  url
    private  String key;
    private String keyWorld;
    private double rank;
    private String title;
    private String content;


    @Override
    public int compareTo(WebPageItem o) {
        return this.rank == o.rank ? this.keyWorld.compareTo(o.keyWorld) : (int) (this.rank - o.rank);
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(key);
        out.writeUTF(keyWorld);
        out.writeDouble(rank);
        out.writeUTF(title);
        out.writeUTF(content);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.key=in.readUTF();
        this.keyWorld = in.readUTF();
        this.rank = in.readDouble();
        this.title = in.readUTF();
        this.content = in.readUTF();
    }
}
